package com.example.web.controller;


import java.util.HashMap;
import java.util.Map;

import javax.jms.Topic;

import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.web.config.QueueProducer;
import com.example.web.entity.Student;

import lombok.Data;

@RestController
public class ProviderController {
	@Autowired
	private QueueProducer queueProducer;
	@Autowired
	Topic  t;
	
	// 注入存放消息的队列，用于下列方法一

	@GetMapping("/value")
	public String value() {
		String queueName = "QUEUE_RECEIVE_ADD_FIREND"; // 自定义队列名称
		Student student = new Student();
		student.setName("小明");
		student.setAge(11);
		queueProducer.sendObjectMessage(queueName, student); // 发送到MQS
		return "消息已经发送";
	}

	
	@GetMapping("/value2")
	public String value2() {
		String queueName = "topic_RECEIVE_ADD_FIREND";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", "adad");
		map.put("age", "asdasd");
		Student student = new Student();
		student.setName("小明");
		student.setAge(11);
		
		queueProducer.sendMapMessage(queueName, map);
		return"瞎几把搞";
	}
	@GetMapping("/value3")
	public String  value3(){
		Topic t = new ActiveMQTopic("topic_RECEIVE_ADD_FIREND");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", "adad");
		map.put("age", "asdasd");
		queueProducer.sendObjectMessage(t, map);
		return "asd";
	}
	
}
